package greetings

import (
	"io/ioutil"
	"log"
	"os"
	"path/filepath"

	yaml "gopkg.in/yaml.v2"
)

type YamlDemo struct {
	ZooList Zookeeper `yaml:"zookeeper"`
}

type Zookeeper struct {
	Server string `yaml:"servers"`
	Remark string `yaml:"remark"`
}

func LoadYamlConfig(f string) {

	filepath, _ := filepath.Abs(f)
	file, err := os.Open(filepath)
	if err != nil {
		panic("load file error:" + filepath)
	}
	data, err := ioutil.ReadAll(file)
	if err != nil {
		panic("read file error:" + filepath)
	}

	t := YamlDemo{}
	err = yaml.Unmarshal([]byte(data), &t)
	if err != nil {
		panic("read file map error:" + filepath)
	}
	log.Println("map: ", t)
}
